import time

def calcTime(func):
    '''
    函数修饰器, 用来计算求出最小生命值所需要的时间
    最终返回一个 list [temp, time_sum]
    '''

    def warpper(*args, **kwds):
        time_start = time.perf_counter()
        temp = func(*args, **kwds)
        time_end = time.perf_counter()
        time_sum = time_end - time_start
        return [temp, time_sum * 1000]

    return warpper

class GetSortNums:
    def __init__(self , list_in):
        self.list_in = list_in
        self.out = []

    @calcTime
    def permute(self):
        def backtrack(first=0):
            # 所有数都填完了
            if first == n:
                self.out.append(self.list_in[:])
            for i in range(first, n):
                # 动态维护数组
                self.list_in[first], self.list_in[i] = self.list_in[i], self.list_in[first]
                # 继续递归填下一个数
                backtrack(first + 1)
                # 撤销操作
                self.list_in[first], self.list_in[i] = self.list_in[i], self.list_in[first]

        n = len(self.list_in)
        backtrack()
        return self.out

    def show(self):
        print("待排序为:" , self.list_in)
        print("全排序数目为:{0}，具体的全排序序列为:{1}".format(len(self.out) , self.out))

if __name__ == "__main__":
    list0 = [1,2,3]
    test0 = GetSortNums(list0)
    print(test0.permute())
    test0.show()